package su.jet.irc.client.domain;

import su.jet.irc.client.service.ClientService;
import su.jet.irc.client.service.Authenticator;
import su.jet.irc.client.service.MessageHandler;
import su.jet.irc.client.service.WriteService;
import su.jet.irc.client.service.ReceiveService;

public class ClientApplication {
	private ClientService clientService;
	private Authenticator authenticator;
	private ReceiveService receiveService;
	private WriteService writeService;
	private MessageHandler messageHandler;
	
	public ClientApplication(ClientService clientService) {
		this.clientService = clientService;
	}
	
	public static void main(String[] args) {
		ClientService clientService = new ClientService();
		ClientApplication application = new ClientApplication(clientService);
		application.initServices();
	}
	
	public void initServices() {
		clientService.connect();
		authenticator = clientService.getAuthenticator();
		while (true) {
			authenticator.getUserInfoFromConsole();
			if (authenticator.authentificate()) {
				messageHandler = clientService.getMessageHandler(authenticator.getUser());
				receiveService = clientService.getReceiveService(messageHandler);
				receiveService.start();
				writeService = clientService.getWriteService(messageHandler);
				writeService.runConsoleInput();
				break;
			}
		}
	}

}
